function l = reallines(filepath)
if nargin == 0
    filepath = pwd;
end
if iscell(filepath)
    l = 0;
    for i = 1:numel(filepath)
        l = l + reallines(filepath{i});
    end
    return
end
l = 0;
if nargin == 0, filepath = cd; end

if ~exist(filepath, 'file')
    error([filepath ' is not a file or directory']);
end

if exist(filepath, 'dir')
    files = dir(filepath);
    for i = 1:numel(files)
        file = files(i);
        if ~strcmp(file.name, '.') && ~strcmp(file.name, '..')
            l = l + reallines([filepath, '/', file.name]);
        end
    end
else
    if length(filepath) > 2 && filepath(end) == 'm' && filepath(end-1) == '.'
        l = getfilereallines(filepath);
    end
end
end


function l = getfilereallines(filename)
fid = fopen(filename, 'r');
if fid<0
    error(['Can''t open file for reading (' filename ')'])
end

l = 0;
while ~feof(fid)
    t = fgetl(fid);
    
    for i = 1:numel(t)
        if t(i) ~= ' '
            break;
        end
    end
    if numel(t) && i < numel(t) && t(i) ~= '%'
        l = l + 1;
    end
end
fclose(fid);
end
